import request from '@/utils/request.js'

/**
 * 参数列表
 * @param {*} id 分类 ID
 * @param {*} sel [only,many],通过 only 或 many 来获取分类静态参数还是动态参数
 * @returns
 */
export const getAttributesList = (id, sel) => {
  return request({
    url: `categories/${id}/attributes`,
    params: {
      sel
    }
  })
}

/**
 * 编辑提交参数
 * @param {*}
 *    id: 分类 ID
 *    attrId:属性 ID
 *    {attr_name:新属性的名字, attr_sel:属性的类型[many或only], attr_vals: 参数的属性值}
 * @returns
 */
export const putAttributes = (id, attrId, data) => {
  return request({
    url: `categories/${id}/attributes/${attrId}`,
    method: 'PUT',
    data
  })
}

/**
 * 添加动态参数或者静态属性
 * @param {*}
 *    id: 分类 ID
 *    attrId:属性 ID
 *    {attr_name:参数名称, attr_sel:属性的类型[many或only]}
 * @returns
 */
export const addAttributes = (id, attr_name, attr_sel) => {
  return request({
    url: `categories/${id}/attributes`,
    method: 'POST',
    data: {
      attr_name,
      attr_sel
    }
  })
}

/**
 * 删除参数
 * @param {*}
s * @returns
 */
export const delAttributes = (id, attrid) => {
  return request({
    url: `categories/${id}/attributes/${attrid}`,
    method: 'DELETE'
  })
}

/**
 * 根据 ID 查询参数
 * @param {*}
s * @returns
 */
export const getAttributesById = (id, attrid, attr_sel) => {
  return request({
    url: `categories/${id}/attributes/${attrid}`,
    method: 'GET',
    params: {
      attr_sel
    }
  })
}
